package com.asset.dispoal.address;

import com.asset.dispoal.address.api.AddressService;
import com.asset.dispoal.address.dto.SysAddressRequest;
import com.asset.dispoal.address.dto.SysAddressResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tech.mhuang.pacebox.springboot.core.permission.annotation.Permission;
import tech.mhuang.pacebox.springboot.protocol.Result;

import java.util.List;

/**
 * @author qr
 * @date 2022/2/16$
 */
@RestController
@Api(value = "地址配置", tags = "地址配置")
@RequestMapping("gb/address")
public class AddressController {

    @Autowired
    AddressService addressService;

    @Permission(code = "regionalManger:add")
    @PostMapping("insert")
    @ApiOperation(value = "添加地址", notes = "添加地址")
    public Result insert(@RequestBody SysAddressRequest request) {
        addressService.insert(request);
        return Result.ok();
    }

    @Permission(code = "regionalManger:update")
    @PostMapping("update")
    @ApiOperation(value = "修改地址", notes = "修改地址")
    public Result update(@RequestBody SysAddressRequest request) {
        addressService.update(request);
        return Result.ok();
    }

    @Permission(code = "regionalManger:del")
    @PostMapping("delete")
    @ApiOperation(value = "删除地址", notes = "删除地址")
    public Result delete(@RequestBody SysAddressRequest request) {
        addressService.delete(request);
        return Result.ok();
    }

    @Permission(code = "regionalManger:query", param = "")
    @GetMapping("queryAll")
    @ApiOperation(value = "查询全部地址", notes = "查询全部地址")
    public Result<List<SysAddressResponse>> queryAll(SysAddressRequest request) {
        return addressService.queryAll(request);
    }

    @Permission(code = "regionalManger:query")
    @GetMapping("queryById")
    @ApiOperation(value = "根据id查询", notes = "根据id查询")
    public Result<SysAddressResponse> queryById(String code) {
        return addressService.queryById(code);
    }
}
